﻿<Window x:Class="LoghogInterface.SettingsEdit"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:res="clr-namespace:LoghogInterface.Properties"
        xmlns:my="clr-namespace:LoghogInterface"
        Title="{x:Static res:Resources.SetEdit}" Height="358" Width="731" MinHeight="300" MinWidth="700">

    <Window.Resources>
        <Style  TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="#19000000"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="10" />
            <RowDefinition Height="306*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="165" />
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="481*" />
        </Grid.ColumnDefinitions>
        <Grid.Resources>
            <my:BoolToVisibilityConverter x:Key="BoolToVis" />
        </Grid.Resources>

        <TreeView Grid.Column="1" Grid.Row="1">
            <TreeViewItem Name="LBLawUser" Header="{x:Static res:Resources.EditLawGroup}" />
            <TreeViewItem Name="LBGroupUser" Header="{x:Static res:Resources.GroupUsers}"/>
            <TreeViewItem Header="Подключения">
                <TreeViewItem Name="LBEMail" Header="{x:Static res:Resources.Mail}"/>
                <TreeViewItem Name="LBBD" Header="{x:Static res:Resources.ConSQL}"/>
            </TreeViewItem>
            <TreeViewItem Name="LBTag" Header="{x:Static res:Resources.SetTags}"/>
            <TreeViewItem Name="LBFilters" Header="{x:Static res:Resources.Filts}"/>
        </TreeView>
        
        <!--Права пользователей-->
        <Grid  HorizontalAlignment="Left"  
               Name="GLawUser" VerticalAlignment="Top"
               Visibility="{Binding IsSelected, ElementName=LBLawUser,Converter={StaticResource BoolToVis}}"
               Grid.Column="3" 
               Grid.Row="1">

            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="35" />
            </Grid.RowDefinitions>

            <DataGrid VerticalScrollBarVisibility="Auto" 
                      HorizontalScrollBarVisibility="Auto"
                      ItemsSource="{Binding UserRights}"
                      CanUserAddRows="False"
                      AutoGenerateColumns="False"
                      Grid.Row="0">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="{x:Static res:Resources.GroupName}" Binding="{Binding Path = Name}" IsReadOnly="True" />
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.Read}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Read, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.Add}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Add, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.Export}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Export, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.Import}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding Import, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.AddCollum}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding AddField, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.DelCollum}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding RemoveField, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.AddUsers}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding AddUser, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.DelUsers}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding RemoveUser, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.CreateGroup}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding CreateGroup, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.DelGroup}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding RemoveGroup, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.CreateJournal}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding CreateJournal, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTemplateColumn Header="{x:Static res:Resources.DelJournal}">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding RemoveJournal, UpdateSourceTrigger=PropertyChanged}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>

        <!--Группы пользователей-->
        <Grid Name="GGroupUser" 
              Visibility="{Binding IsSelected, ElementName=LBGroupUser,Converter={StaticResource BoolToVis}}" 
              Grid.Column="3" 
              Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="380*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Left" Margin="0 0 0 5">
                <Button Content="{x:Static res:Resources.toAdd}" Name="BAddUser" Grid.Column="6" Grid.Row="2" />
                <Button Content="{x:Static res:Resources.toDel}" Name="BDelUser" Grid.Column="6" Grid.Row="4"  Margin="5 0 0 0"/>
            </StackPanel>

            <ListBox Name="LBGroups"  Grid.Row="1" Grid.RowSpan="1" AlternationCount="2" ItemsSource="{Binding UserGroups}" />            
        </Grid>
        
        <!--Настройки почты-->
        <Grid Name="GEMail" Visibility="{Binding IsSelected, ElementName=LBEMail,Converter={StaticResource BoolToVis}}" Grid.Column="3" Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="380*" />
                <ColumnDefinition Width="100" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="92*" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>
            <Label Content="{x:Static res:Resources.SerAdress}" Grid.ColumnSpan="2" />
            <TextBox Name="TSerAdress" Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding SMTPServer}" />
            
            <Label Content="{x:Static res:Resources.Port}" Grid.Row="2" Grid.ColumnSpan="2" />
            <TextBox Name="TPort" Grid.Row="3" Grid.ColumnSpan="2" Text="{Binding SMTPPort}" />
            
            <Label Content="{x:Static res:Resources.Adress}" Grid.Row="4" Grid.ColumnSpan="2" />
            <TextBox Name="TAdress" Grid.Row="5" Grid.ColumnSpan="2" Text="{Binding Email}" />
        </Grid>
        
        <!--Настройки тэгов-->
        <Grid Name="GTags" Visibility="{Binding IsSelected, ElementName=LBTag,Converter={StaticResource BoolToVis}}" Grid.Column="3" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
                <RowDefinition Height="30" />
                <RowDefinition Height="252*" />
            </Grid.RowDefinitions>
            <ToolBar Name="toolBar1"  Grid.Row="1">
                <Button Content="{x:Static res:Resources.AddTag}"  Name="BAddTeg" Command="{Binding ShowAddTag}"  />
                <Button Content="{x:Static res:Resources.toDel}"  Name="BDel"   />
                <Button Content="{x:Static res:Resources.Set}"  Name="BSet"  />
            </ToolBar>
            <ListBox Name="LBTags" Grid.Row="2" ItemsSource="{Binding Tags}" />
        </Grid>
        
        <!--Настройки подключения к БД-->
        <Grid Name="GBD" Visibility="{Binding IsSelected, ElementName=LBBD,Converter={StaticResource BoolToVis}}" Grid.Column="3" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>
           
            <StackPanel Grid.Row="0"
                        Orientation="Vertical"
                        Margin="0 0 5 0">
                <Label Content="{x:Static res:Resources.DatabaseServer}"  Name="label2" />
                <TextBox Name="TSerBD"  Text="{Binding ServerDatabase}" />
            </StackPanel>
            
            <StackPanel Grid.Row="1"
                        Orientation="Vertical"
                        Margin="0 0 5 0">
                <Label Content="Имя базы данных" />
                <TextBox Text="{Binding NameDatabase}" />
            </StackPanel>

            <StackPanel Grid.Row="2"
                        Orientation="Vertical"
                        Margin="0 0 5 0">
                <Label Content="{x:Static res:Resources.User}" Name="label1"  />
                <TextBox Name="textBox1"  Text="{Binding UserDatabase}" />
            </StackPanel>

            <StackPanel Grid.Row="3"
                        Orientation="Vertical"
                        Margin="0 0 5 0">
                <Label Content="{x:Static res:Resources.Password}" Name="label3"    />
                <TextBox Name="textBox2"  Text="{Binding PasswordDatabase}" />
            </StackPanel>
        </Grid>

        <!--Фильтры-->
        <Grid Name="GFilters" 
              Visibility="{Binding IsSelected, ElementName=LBFilters,Converter={StaticResource BoolToVis}}" 
              Grid.Column="3" 
              Grid.Row="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="40" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="380*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Vertical" Grid.Row="0">
            <Button Content="{x:Static res:Resources.toAdd}" 
                    Command="{Binding WindowAddFilter}"
                    Name="BAddFiltr" 
                    Grid.Row="1" 
                    Grid.Column="2" 
                    Height="25" 
                    HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0 0 0 5" />
            <ListBox Grid.Row="2" Name="listBox2" ItemsSource="{Binding MailingFilters}" />
            </StackPanel>
        </Grid>
        <StackPanel Grid.Row="2" Grid.Column="3"
                    Margin="0 5 0 5"
                    Orientation="Horizontal" 
                    HorizontalAlignment="Right"
                    VerticalAlignment="Bottom">
            <Button Content="Сохранить" Grid.Column="0" Command="{Binding ApplySettings}" Width="80" Height="25" Click="Button_Click" />
            <Button Content="Применить" Grid.Column="0" Command="{Binding ApplySettings}" Width="80" Height="25"  />
            <Button Content="Отмена" Grid.Column="0" Width="70" Height="25" Click="CloseWindow" />
        </StackPanel>
    </Grid>
</Window>
